package top;

/**
 *
 * 搞笑搜索二维矩阵
 *
 * @author chenyw
 * @date 2022/7/19 20:23
 */
public class Top240searchMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int i = m - 1;
        int j = 0;
        while (i >= 0 && j < n) {
            if (matrix[i][j] == target) {
                return true;
            }
            if (matrix[i][j] > target) {
                i--;
            } else {
                //逆序用else不能再写一个单独的if，因为i在变化
                j++;
            }
        }
        return false;
    }
}
